home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / d3_draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  4.7 KB  |  196 lines

  1. /*****************************************************************************
  2.   FILE           : d3_draw.c
  3.   SHORTNAME      : draw.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : routines for cube and line drawing
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Ralf Huebner
  10.   DATE           : 1.12.1991
  11.  
  12.   CHANGED BY     : Sven Doering
  13.   IDENTIFICATION : @(#)d3_draw.c    1.12 3/2/94
  14.   SCCS VERSION   : 1.12
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <math.h>
  24. #include <X11/Xlib.h>
  25. #include <X11/X.h>
  26. #include <X11/Xutil.h>
  27. #include <X11/Xos.h>
  28.  
  29. #include "glob_typ.h"    /*  Kernel constant and type definitions  */
  30. #include "kr_ui.h"    /*  Kernel interface functions    */
  31.  
  32.  
  33. #include "d3_global.h"
  34. #include "d3_anageo.h"
  35. #include "d3_shade.h"
  36. #include "d3_zgraph.h"
  37. #include "d3_graph.h"
  38. #include "d3_point.h"
  39. #include "d3_main.h"
  40.  
  41. #include "d3_draw.ph"
  42.  
  43. /*****************************************************************************
  44.   FUNCTION : d3_draw_wireframeLine
  45.  
  46.   PURPOSE  : draws a link for the wireframe model
  47.   RETURNS  : 
  48.   NOTES    :
  49.  
  50. ******************************************************************************/
  51.  
  52.  
  53. void d3_draw_wireframeLine (float *v1, float *v2)
  54. {
  55.     int xp1, yp1, xp2, yp2;
  56.  
  57.     xp1 = floor (v1[0] + 0.5);
  58.     yp1 = floor (v1[1] + 0.5);
  59.     xp2 = floor (v2[0] + 0.5);
  60.     yp2 = floor (v2[1] + 0.5);
  61.     d3_drawLine (xp1, yp1, xp2, yp2);
  62. }
  63.  
  64.  
  65.  
  66.  
  67. /*****************************************************************************
  68.   FUNCTION : d3_draw_wireframeCube
  69.  
  70.   PURPOSE  : draws a unit for the wireframe model
  71.   RETURNS  : 
  72.   NOTES    :
  73.  
  74. ******************************************************************************/
  75.  
  76.  
  77.  
  78. /* void d3_draw_wireframeCube (float (*c)[4]) */
  79. void d3_draw_wireframeCube (cube c)
  80. {
  81.     int i, xp1, yp1, xp2, yp2;
  82.  
  83.     for (i=0; i<ANZ_LINES; i++) {
  84.          xp1 = c [d3_cube_lines [i][0]][0];
  85.          yp1 = c [d3_cube_lines [i][0]][1];
  86.          xp2 = c [d3_cube_lines [i][1]][0];
  87.          yp2 = c [d3_cube_lines [i][1]][1];
  88.          d3_drawLine (xp1, yp1, xp2, yp2);
  89.     }
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /*****************************************************************************
  97.   FUNCTION : d3_draw_solidLine
  98.  
  99.   PURPOSE  : draws a link for the solid model
  100.   RETURNS  : 
  101.   NOTES    :
  102.  
  103. ******************************************************************************/
  104.  
  105.  
  106. void d3_draw_solidLine (vector v1, vector v2)
  107. {
  108.     int xp, yp, i;
  109.     float my, my_step, dx, dy, zp;
  110.     vector v, w;
  111.  
  112.  
  113.     dx = fabs (v2[0] - v1[0]);
  114.     dy = fabs (v2[1] - v1[1]);
  115.     if (dx > dy)
  116.         my_step = 1.0 / dx;
  117.     else
  118.         my_step = 1.0 / dy;
  119.     for (i=0; i<4; i++)
  120.         w[i] = v2[i] - v1[i];
  121.     my = 0.0;
  122.     while (fabs (my) <= 1.0) {
  123.         for (i=0; i<4; i++)
  124.             v[i] = v1[i] + my * w[i];
  125.         xp = (int) (v[0]+0.5);
  126.         yp = (int) (v[1]+0.5);
  127.         if ((xp >= d3_clipWindow.x0) && (yp >= d3_clipWindow.y0) 
  128.           && (yp < d3_clipWindow.y1) && (xp < d3_clipWindow.x1)) {
  129.             d3_readZbuffer (xp, yp, &zp);
  130.             if (v[2] < zp) {
  131.                 d3_putPixel (xp, yp);
  132.                 d3_writeZbuffer (xp, yp, v[2]);
  133.         }
  134.         }
  135.         my += my_step;
  136.     }
  137. }
  138.  
  139.  
  140.  
  141.  
  142. /*****************************************************************************
  143.   FUNCTION : d3_draw_solidCube
  144.  
  145.   PURPOSE  : draws a unit for the solid model
  146.   RETURNS  : 
  147.   NOTES    :
  148.   UPDATE   : 3.3.93  shading for activation
  149.  
  150. ******************************************************************************/
  151.  
  152.  
  153.  
  154. void d3_draw_solidCube (cube c, vector vp, vector lp, int unit_no)
  155. {
  156.     int pi, vi;
  157.     d3_polygon_type p;
  158.     unsigned long color;
  159.     vector normal;
  160.     float col_val;
  161.     static unsigned long shades[6] = {0, -2, 2, 0, -2, 2};
  162.  
  163.     for (pi=0; pi<6; pi++) {
  164.         d3_normalVector (normal, c[d3_vertex_index[pi][0]],
  165.                                  c[d3_vertex_index[pi][1]],
  166.                                  c[d3_vertex_index[pi][2]]);
  167.  
  168.         if (d3_state.unit_mode.color == nothing_on) {
  169.             d3_shadeIntens (&d3_intens, c[d3_vertex_index[pi][0]], normal, lp);
  170.             color = d3_intens_to_grayval (d3_intens);
  171.         } else {
  172.             d3_getColorValue (d3_state.unit_mode.color, unit_no, &col_val);
  173.             color = (long) d3_value_to_color (col_val) + 3 + shades[pi];
  174.         }
  175.         d3_setColor (color);
  176.         p.n = 4;
  177.         for (vi=0; vi<4; vi++) {
  178.             p.vert[vi][0] = c[d3_vertex_index[pi][vi]] [0];
  179.             p.vert[vi][1] = c[d3_vertex_index[pi][vi]] [1];
  180.             p.vert[vi][2] = c[d3_vertex_index[pi][vi]] [2];
  181.         }
  182.         d3_drawPoly (&p);
  183.         d3_flushPixels ();
  184.     }
  185. }
  186.  
  187.  
  188. /* end of file */
  189. /* lines:*/
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.